package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.SignStore;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ISignStoreService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("products")
public class SignStoreController {

    @Autowired
    ISignStoreService signStoreService;


    //分页
    @GetMapping
    public PageInfo listProduct(QueryObject qo){
        PageInfo pageInfo = signStoreService.query(qo);
        return pageInfo;
    }

    //根据商品id 查询商品价值积分
    @GetMapping("/selectProductById")
    public JSONResult product(SignStore record){
        //商品对象
        JSONResult json = new JSONResult();
        SignStore signStore = signStoreService.selectOne(record);
        json.setResult(signStore);
        return json;
    }

    //查询用户兑换的商品
    @GetMapping("/user")
    public List<SignStore> listProductByUser(){
        User user = UserContext.getCurrentUser();
        List<SignStore> products = signStoreService.selectProducts(user.getId());
        return products;
    }

    //查询当前页面是否已登录
    @GetMapping("/userId")
    public JSONResult selectUserId(){
        JSONResult result = new JSONResult();
        User user = UserContext.getCurrentUser();
        result.setResult(user);
        return result;
    }


}
